/*
* 判断一颗二叉树是否为轴对称的，迭代做法
* https://leetcode.cn/problems/symmetric-tree/submissions/
* */
class IsSymmetricNotDiGui {
    public boolean isSymmetric(TreeNode root) {
        return isSymmetricChild(root,root);

    }
    public boolean isSymmetricChild(TreeNode leftTree,TreeNode rightTree){
        Queue<TreeNode> q=new LinkedList<>();
        q.offer(leftTree);
        q.offer(rightTree);
        while(!q.isEmpty()){
            leftTree=q.poll();
            rightTree=q.poll();
            if(leftTree==null&&rightTree==null){
                continue;
            }
            if(leftTree==null&&rightTree!=null){
                return false;
            }
            if(leftTree!=null&&rightTree==null){
                return false;
            }
            if(leftTree.val!=rightTree.val){
                return false;
            }
            q.offer(leftTree.left);
            q.offer(rightTree.right);
            q.offer(leftTree.right);
            q.offer(rightTree.left);
        }
        return true;
    }
}